"""
-*- coding: utf-8 -*-
@Time    : 2021/4/29 19:40
@Author  : Hu
@Email   : 624611978@qq.com
@File    : 作业2.py
"""
import string
import random
with open("file.txt","w+",encoding="utf-8") as f:
    for i in range(10**4):
        f.write("".join(random.choices(string.ascii_lowercase,k=random.randint(1,49)))+"\n")

def openbig(path):
    with open(path,"r",encoding="utf-8") as f:
        fLen = 0 #存放长度
        lineCount = 0 #存放行数
        while True:
            fRead = f.readline()
            lineCount += 1
            if fRead:
                if fLen<len(fRead):
                    fLen = len(fRead) #当前行长度更长则覆盖
                    fLenCount = lineCount #存放当前的行数
                yield
            else:
                print(f"最长的行是第{fLenCount}行，长度为{fLen}")
                break

a = openbig("file.txt")
for i in a:
    pass